import SocketServer,sys,re,time,thread,threading,os,socket,random
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 7187))
s.send("REGISTER\r\n")
time.sleep(0.2)
resp = s.recv(1024)
print 'Resposta: ',resp.strip()
#s.send("REGISTER\r\n")
#time.sleep(0.2)
#resp = s.recv(1024)
#print 'Resposta: ',resp.strip()

if resp.strip()=='OK':
        print "REGISTER OK"
	s.send("LIST\r\n")
	Mcache = []
	time.sleep(0.2)
        data = s.recv(1024)
	data = data.strip().split('\r\n')
	print len(data)
	Mcache =  data
	for ip in Mcache:
		print 'voce esta tentando conectar em '+ ip
	s.send("EXIT\r\n")
#        while data.strip() != 'FINISH':
#		Mcache.append(data.strip())
#		data = s.recv(1024)
#		print Mcache
#	
#else:
#        print "REGISTER Falhou"
s.close()

#while 1:
#	chunk = s.recv(1024)
#        if not chunk:
#            sys.stdout.write("@")
#            time.sleep(0.1)
#
#s.send("LIST\r\n")
#data = s.recv(1024)
#print data
#time.sleep(0.1)
#data = s.recv(1024)
#print data

